$.getScript("targetsConnect/public.js",function(){
	sendConnectAjax("#connectZhuTime_select",create_Connectzhu);
}); 

$("#connectZhusubmit").click(function(){
	$("#connectZhu").remove();
	sendConnectAjax("#connectZhuTime_select",create_Connectzhu);
});

function prepare1(dataArray,key) {
	var list = [];
	$.each(dataArray,function(i,item){
		if(item)
			list.push({y:item[key],map:item});
		else
			list.push({y:0});
	});
	return list;
};

function create_Connectzhu(xml){
	var div = $("<div>").attr("id","connectZhu").addClass("graphCss");
	$("#Connectc_info").append(div).height($("#contentWarpper").height()-$(".top_menu").height());
	var x_name=[];var data4=[];var data5=[];var data6=[];var noturn=[];var date=[];var vdnArr={};var temp = "";
    var ii = -1;
    var size=$("#Connectc_info").parent().parent().data("highChartNum");
	  	$(xml).find("row").each(function(i){
			var vdnMap={};
  			var col1 = $(this).get(0).attributes.getNamedItem("col1").nodeValue;
			var col3 = $(this).get(0).attributes.getNamedItem("col2").nodeValue;//vdn
	  		var col4 = parseInt($(this).get(0).attributes.getNamedItem("col3").nodeValue);//呼入数
	  		var col5 = parseInt($(this).get(0).attributes.getNamedItem("col4").nodeValue);//接通数
		  	var col6 = $(this).get(0).attributes.getNamedItem("col5").nodeValue;//接通率
			col6=parseFloat(col6)*100;
	 		if(col6.toString().split('.')[1])
	 			col6=col6.toFixed(2);
	 		vdnMap.vdn=col3;
		  	vdnMap.data4=col4;
		  	vdnMap.data5=col5;
		  	vdnMap.data6=col6;
		  	vdnMap.noturn=col4-col5;
			if(temp != col1){
    			ii++;
    			if(ii+1>size && size!=0)
	  				return false;
    			temp=col1;
    			x_name.push(col1);
    		}
    		var list = [];
    		if(vdnArr[col3]){
    			list = vdnArr[col3];
    		}
    		list[ii] = vdnMap;
    		vdnArr[col3] = list;
	  	});
	  	var xLength=x_name.length;
	  	$.each(vdnArr,function(key,value){
	    	if(!value[xLength-1]){
	    		value[xLength-1]=null;
	    		vdnArr[key]=value;
	    	}
    	});

	  	var serviceList=[];
	  	$.each(vdnArr,function(key,value){
		  	var noturn={
                name: '未接通数',
                data: prepare1(value,'noturn'),
                stack:key,
                dataLabels: {
                    color:CONFIG_PARAMS.GraphFontColor
                }
        	};
            var turn={
                name: '接通数',
                data: prepare1(value,'data5'),
                stack:key,
                dataLabels: {
                    color:CONFIG_PARAMS.GraphFontColor
                }
            };
			serviceList.push(noturn);
			serviceList.push(turn);
	  	});
        $('#connectZhu').highcharts({
            chart: {
                type: 'column',
                backgroundColor:CONFIG_PARAMS.GraphBackColor
            },
            title: {
                text: ''
            },
            subtitle: {
                text: ''
            },
            xAxis: {
                categories: x_name,
	            labels : { 
            		style:{
            			color:CONFIG_PARAMS.GraphFontColor
            		}
            	}
            },
            yAxis: {
                title: {
                    text: '数量',
                    style:{
	            		color:CONFIG_PARAMS.GraphFontColor
	            	}
                },
                labels : { 
            		style:{
            			color:CONFIG_PARAMS.GraphFontColor
            		}
            	},stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || CONFIG_PARAMS.GraphFontColor
                    }
                }
            },
            legend:{
	        	itemStyle: {
                	color: CONFIG_PARAMS.GraphFontColor
            	},
            	labels : { 
            		style:{
            			color:CONFIG_PARAMS.GraphFontColor
            		}
            	},
            	enabled: false
	        },
	         tooltip: {
				formatter: function() {
					var s='<b>'+ this.x +'</b>';
					s += '<br/><span style="color:#C709F7">vdn: '+ this.point.map.vdn +'</span>';
					s += '<br/><span style="color:#22B14C">未接通数: '+ this.point.map.noturn +'</span>';
                	s += '<br/><span style="color:#71BCFA">接通数: '+ this.point.map.data5 +'</span>';
                	s += '<br/><span style="color:red">接通率: '+ this.point.map.data6 +'%</span>';
	                return s;
	            }
            },
            plotOptions: {
                column: {
                	stacking: 'normal',
                    dataLabels: {
                        enabled: true,
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                		formatter:function(){
                			return this.y || "";
                		}
                    }
                }
            },
            series: serviceList
        });
}